package vip.xiaomoli.nurse.component;

import vip.xiaomoli.nurse.model.Api;
import vip.xiaomoli.nurse.model.FieldWrapper;

import java.util.*;

public class InjectContainer {

    /**
     * Api---1:N---ParamValue---1:N---field
     */
    private static ThreadLocal<Map<Api, Map<Object, List<FieldWrapper>>>> container = ThreadLocal.withInitial(HashMap::new);

    public static void put(Api api, Object paramValue, FieldWrapper fieldWrapper) {
        Map<Api, Map<Object, List<FieldWrapper>>> apiMap = container.get();
        Map<Object, List<FieldWrapper>> paramValueMap = apiMap.computeIfAbsent(api, f -> new HashMap<>());
        List<FieldWrapper> fieldList = paramValueMap.computeIfAbsent(paramValue, f -> new ArrayList<>());
        fieldList.add(fieldWrapper);
    }

    public static Map<Api, Map<Object, List<FieldWrapper>>> get() {
        return container.get();
    }

    public static void remove() {
        container.remove();
    }

}
